export const toCamelCase = (str: string): string => {
  return str.replace(/[-_](\w)/g, (_, c) => c.toUpperCase());
};
export function formatBytes(bytes: number, decimals: number = 2): string {
  if (bytes === 0) return "0 Bytes";

  const k = 1024; // 1 KB = 1024 Bytes
  const dm = decimals < 0 ? 0 : decimals;
  const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];

  const i = Math.floor(Math.log(bytes) / Math.log(k));

  return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
}
function convertLargeNumbers(obj: any): any {
  if (typeof obj === "object" && obj !== null) {
    if (Array.isArray(obj)) {
      return obj.map(convertLargeNumbers);
    }
    const newObj: { [key: string]: any } = {};
    for (const [key, value] of Object.entries(obj)) {
      if (
        typeof value === "number" &&
        (value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER)
      ) {
        newObj[key] = BigInt(value);
      } else if (typeof value === "object" && value !== null) {
        newObj[key] = convertLargeNumbers(value);
      } else {
        newObj[key] = value;
      }
    }
    return newObj;
  }
  return obj;
}

export { convertLargeNumbers };
